﻿using LoD.Contracts;


namespace LoD.WPClientLibrary.Animations {
    public class FrameLoop : Animation {
        private double _startTime;

        public FrameLoop(Contracts.Animation animation, Direction direction)
            : this(((int)direction * 8) + ((int)animation * 64), 7, 1, 3) { if (animation == Contracts.Animation.Stand) this.End = 0; }

        public FrameLoop(int start, int end, int direction) : this(start, end, direction, 30) { }

        public FrameLoop(int start, int end, int direction, double speed) {
            Animating = true;
            this.Start = start;
            this.End = end;
            this.Direction = direction;
            this.Speed = speed;
        }

        public int Start { get; set; }
        public int End { get; set; }
        public int Direction { get; set; }
        public double Speed { get; set; }

        public override int ModifyFrame(int current) {
            if (!(++this._startTime > this.Speed)) return current;
            this._startTime = 0;
            current += this.Direction;
            if (current > this.End) current = this.Start;
            else if (current < this.Start) current = this.End;
            return current;
        }
    }
}